databaseChangeLog:
  - changeSet:
      id: first_migration
      author: nikolay.pushkin
      changes:
        # Компании
        - createTable:
            tableName: companies
            remarks: Компании
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: title
                  type: varchar(50)
                  constraints:
                    nullable: false
              - column:
                  name: is_active
                  type: boolean
                  defaultValue: true
                  constraints:
                    nullable: false
        # Отделы
        - createTable:
            tableName: departments
            remarks: Отделы
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
                  constraints:
                    unique: true
              - column:
                  name: title
                  type: varchar(50)
                  constraints:
                    nullable: false
              - column:
                  name: is_active
                  type: boolean
                  defaultValue: true
                  constraints:
                    nullable: false
              - column:
                  name: company_id
                  type: integer
                  constraints:
                    foreignKeyName: company_department_fk
                    referencedTableName: companies
                    referencedColumnNames: id
        # Должности (справочник)
        - createTable:
            tableName: posts
            remarks: Должности
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
                  constraints:
                    unique: true
              - column:
                  name: title
                  type: varchar(50)
                  constraints:
                    nullable: false
              - column:
                  name: is_active
                  type: boolean
                  defaultValue: true
                  constraints:
                    nullable: false
        # Сотрудники Физические лица
        - createTable:
            tableName: employees
            remarks: Сотрудники
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
                  constraints:
                    unique: true
              - column:
                  name: name
                  type: varchar(50)
                  remarks: Имя
                  constraints:
                    nullable: false
              - column:
                  name: surname
                  type: varchar(50)
                  remarks: Отчество
                  constraints:
                    nullable: true
              - column:
                  name: lastname
                  type: varchar(50)
                  remarks: Фамилия
                  constraints:
                    nullable: false
              - column:
                  name: is_active
                  type: boolean
                  defaultValue: true
                  constraints:
                    nullable: false
              - column:
                  name: company_id
                  type: integer
                  constraints:
                    nullable: false
        # Штатное расписание
        - createTable:
            tableName: staff
            remarks: Штатное расписание
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: title
                  type: varchar(50)
                  constraints:
                    nullable: false
              - column:
                  name: is_active
                  type: boolean
                  defaultValue: true
                  constraints:
                    nullable: false
              - column:
                  name: department_id
                  type: integer
                  constraints:
                    foreignKeyName: staff_department_fk
                    referencedTableName: departments
                    referencedColumnNames: id
              - column:
                  name: post_id
                  type: integer
                  constraints:
                    foreignKeyName: staff_post_fk
                    referencedTableName: posts
                    referencedColumnNames: id
        # Сотрудники-вакантная должность в штатном расписании (многие ко многим)
        - createTable:
            tableName: employee_staff
            remarks: Сотрудники должности
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
              - column:
                  name: staff_id
                  type: integer
                  constraints:
                    foreignKeyName: employee_staff_fk
                    referencedTableName: staff
                    referencedColumnNames: id
              - column:
                  name: employee_id
                  type: integer
                  constraints:
                    foreignKeyName: post_employee_fk
                    referencedTableName: employees
                    referencedColumnNames: id
        # Номера телефонов (один ко многим)
        - createTable:
            tableName: phones
            remarks: Номера телефонов
            columns:
              - column:
                  name: id
                  type: integer
                  autoIncrement: true
              - column:
                  name: phoneNumber
                  type: varchar(11)
                  constraints:
                    nullable: false
              - column:
                  name: employee_id
                  type: integer
                  constraints:
                    foreignKeyName: phone_employee_fk
                    referencedTableName: employees
                    referencedColumnNames: id

  - include:
      file: db.changelog-24-03-2024.sql
      relativeToChangelogFile: true